# Compiler #
CC = g++
CFLAGS = -W -Wall -std=c++0x
LIBRARIES = -lboost_filesystem -lboost_system

# Directories #
BIN_DIR = bin
INC_DIR = include
OBJ_DIR = obj
SRC_DIR = src
LIB_DIR = 
TAR_FILES = makefile

# Paths settings #
vpath %.hpp $(INC_DIR)
vpath %.cpp $(SRC_DIR)

# File sets #
SOURCES = $(foreach X, $(shell find $(SRC_DIR) -type d ! -regex '.*.svn.*'), \
$(patsubst $(SRC_DIR)/%, %, $(wildcard $(X)/*.cpp)))
HEADERS = $(foreach X, $(INC_DIR), \
$(foreach Y, $(shell find $(X) -type d ! -regex '.*.svn.*'), \
$(patsubst $(X)/%, %, $(wildcard $(Y)/*.hpp))))
OBJECTS = $(patsubst %.cpp, $(OBJ_DIR)/%.o, $(SOURCES))
DEPENDENCIES_FILE = makefile_dependencies

# Targets #
BIN = application
TAR = Projet_FahrnerFleuryMunsch

# Compilation #

all : $(BIN)

$(BIN) : $(BIN_DIR)/$(BIN)

$(BIN_DIR)/$(BIN) : $(OBJECTS)
	$(CC) $(CFLAGS) $^ -o $@ $(foreach X, $(LIB_DIR), -L$(X)) $(LIBRARIES)

$(OBJECTS) : $(OBJ_DIR)/%.o : %.cpp
	$(CC) $(CFLAGS) $(foreach X, $(INC_DIR), -I$(X)) -c $< -o $@

include $(DEPENDENCIES_FILE)

# Automatic generation of the dependencies file #

$(DEPENDENCIES_FILE) : $(SOURCES) $(HEADERS)
	@echo "Regenerating the dependencies...\n"
	@-makedepend -f- -s"### Dependencies ###" \
	$(foreach X, $(INC_DIR), -I$(X)) \
	$(addprefix $(SRC_DIR)/, $(SOURCES)) \
	-Y > tmp 2> /dev/null && mv tmp $(DEPENDENCIES_FILE)
	@sed s/$(SRC_DIR)/'$$(OBJ_DIR)'/ $(DEPENDENCIES_FILE) > tmp
	@mv tmp $(DEPENDENCIES_FILE)
	@sed s/' include\/'/' '/g $(DEPENDENCIES_FILE) > tmp
	@mv tmp $(DEPENDENCIES_FILE)

# Miscellaneous #

tar : $(BIN_DIR) $(OBJ_DIR) $(INC_DIR) $(SRC_DIR) $(TAR_FILES)
	tar cf $(TAR).tar $^
	gzip -f $(TAR).tar

clean :
	rm -f $(OBJECTS)

mrproper : clean
	rm -f $(BIN_DIR)/*

# DO NOT DELETE
